home *** CD-ROM | disk | FTP | other *** search
/ EuroCD 3 / EuroCD 3.iso / Programming / vbcc / declaration.c < prev    next >
C/C++ Source or Header  |  1998-06-24  |  45KB  |  1,468 lines

  1. /*  $VER: vbcc (declaration.c) V0.4     */
  2.  
  3. #include "vbc.h"
  4.  
  5. static char FILE_[]=__FILE__;
  6.  
  7. #define PARAMETER 8
  8. #define OLDSTYLE 16
  9.  
  10. struct const_list *initialization(struct Typ *,int,int);
  11. int test_assignment(struct Typ *,np);
  12. int return_sc,return_reg,has_return;
  13.  
  14. extern int float_used;
  15. extern void optimize(long,struct Var *);
  16.  
  17. int settyp(int typnew, int typold)
  18. /* Unterroutine fuer declaration_specifiers().              */
  19. {
  20.   static int warned_long_double;
  21.   if(DEBUG&2) printf("settyp: new=%d old=%d\n",typnew,typold);
  22.   if(typold==LONG&&typnew==FLOAT){ error(203); return(DOUBLE);}
  23.   if(typold==LONG&&typnew==DOUBLE){
  24.     if(!warned_long_double){error(204);warned_long_double=1;}
  25.     return(DOUBLE);
  26.   }
  27.   if(typold!=0&&typnew!=INT){error(47);return(typnew);}
  28.   if(typold==0&&typnew==INT) return(INT);
  29.   if(typold==0) return(typnew);
  30.   if(typold==SHORT||typold==LONG) return(typold);
  31.   error(48);
  32.   return(typnew);
  33. }
  34.  
  35. #define dsc if(storage_class) error(49); if(typ||type_qualifiers) error(50)
  36. #define XSIGNED 16384
  37.  
  38. struct Typ *declaration_specifiers(void)
  39. /* Erzeugt neuen Typ und gibt Zeiger darauf zurueck,      */
  40. /* parst z.B. unsigned int, struct bla etc.               */
  41. {
  42.   int typ=0,type_qualifiers=0,notdone,storage_class,hard_reg;
  43.   char *merk,*imerk,sident[MAXI],sbuff[MAXI];
  44.   struct Typ *new=mymalloc(TYPS),*t,*ts;
  45.   struct struct_declaration *ssd;
  46.   struct struct_list (*sl)[];
  47.   size_t slsz;
  48.   struct Var *v;
  49.   storage_class=hard_reg=0;
  50.   new->next=0; new->exact=0;
  51.   do{
  52.     killsp();merk=s;cpbez(buff,0);notdone=0;
  53.     if(DEBUG&2) printf("ts: %s\n",buff);
  54.     if(!strcmp("struct",buff)) notdone=STRUCT;
  55.     if(!strcmp("union",buff)) notdone=UNION;
  56.     if(notdone!=0){
  57.       killsp();
  58.       if(*s!='{'){
  59.     cpbez(sident,1);
  60.     killsp();
  61.     ssd=find_struct(sident,0);
  62.     if(ssd&&*s=='{'&&find_struct(sident,nesting)&&ssd->count>0) error(13,sident);
  63.     if(!ssd||((*s=='{'||*s==';')&&!find_struct(sident,nesting))){
  64.       typ=settyp(notdone,typ);
  65.       ssd=mymalloc(sizeof(*ssd));
  66.       ssd->count=0;
  67.       new->exact=ssd=add_sd(ssd);
  68.       add_struct_identifier(sident,ssd);
  69.     }else{
  70.       new->exact=ssd;
  71.       typ=settyp(new->flags=notdone,typ);
  72.     }
  73.       }else{
  74.     *sident=0;
  75.     typ=settyp(notdone,typ);
  76.     ssd=mymalloc(sizeof(*ssd));
  77.     ssd->count=0;
  78.     new->exact=ssd=add_sd(ssd);
  79.       }
  80.       if(*s=='{'){
  81.     s++;
  82.     killsp();
  83.     slsz=SLSIZE;
  84.     sl=mymalloc(slsz*sizeof(struct struct_list));
  85.     ssd->count=0;
  86.     imerk=ident;
  87.     ts=declaration_specifiers();
  88.     while(*s!='}'&&ts){
  89.       ident=sbuff;
  90.       t=declarator(clone_typ(ts));
  91.       killsp();
  92.       if(*s==':'){
  93.         /*  bitfields werden hier noch ignoriert    */
  94.         np tree;
  95.         if((ts->flags&NQ)!=INT) error(51);
  96.         s++;killsp();tree=assignment_expression();
  97.         if(type_expression(tree)){
  98.           if(tree->flags!=CEXPR) error(52);
  99.           if((tree->ntyp->flags&NQ)<CHAR||(tree->ntyp->flags&NQ)>LONG) error(52);
  100.         }
  101.         if(tree) free_expression(tree);
  102.       }else{
  103.         if(*ident==0) error(53);
  104.       }
  105.       if(type_uncomplete(t)){
  106.         error(14,sbuff);
  107.         freetyp(t);
  108.         break;
  109.       }
  110.       if((t->flags&NQ)==FUNKT)
  111.         error(15,sbuff);
  112.       
  113.       if(*ident!=0){
  114.         int i=ssd->count;
  115.         while(--i>=0)
  116.           if(!strcmp((*sl)[i].identifier,ident))
  117.         error(16,ident);
  118.       }
  119.       (*sl)[ssd->count].styp=t;
  120.       (*sl)[ssd->count].identifier=add_identifier(ident,strlen(ident));
  121.       ssd->count++;
  122.       if(ssd->count>=slsz-1){
  123.         slsz+=SLSIZE;
  124.         sl=realloc(sl,slsz*sizeof(struct struct_list));
  125.         if(!sl){error(12);raus();}
  126.       }
  127.       killsp();
  128.       if(*s==',') {s++;killsp();continue;}
  129.       if(*s!=';') error(54); else s++;
  130.       killsp();
  131.       if(*s!='}'){
  132.         if(ts) freetyp(ts);
  133.         ts=declaration_specifiers();killsp();
  134.       }
  135.     }
  136.     if(ts) freetyp(ts);
  137.     if(ssd->count==0) error(55);
  138.     ident=imerk;
  139.     add_sl(ssd,sl);
  140.     free(sl);
  141.     if(*s!='}') error(56); else s++;
  142.     new->flags=notdone|type_qualifiers;
  143.       }
  144.       notdone=1;
  145.     }
  146.     if(!strcmp("enum",buff)){
  147.       /*  enumerations; die Namen werden leider noch ignoriert    */
  148.       killsp();notdone=1;
  149.       if(*s!='{'){cpbez(buff,1);killsp();}
  150.       if(*s=='{'){
  151.     zlong val; struct Var *v; struct Typ *t;
  152.     val=l2zl(0L);
  153.     s++;killsp();
  154.     while(*s!='}'){
  155.       cpbez(sident,1);killsp();
  156.       if(*sident==0) {error(56);break;}
  157.       t=mymalloc(TYPS);
  158.       t->flags=CONST|INT;
  159.       t->next=0;
  160.       if(find_var(sident,nesting)) error(17,sident);
  161.       v=add_var(sident,t,AUTO,0); /*  AUTO hier klug? */
  162.       if(*s=='='){
  163.         s++;killsp();
  164.         v->clist=initialization(v->vtyp,0,0);
  165.         val=zi2zl(v->clist->val.vint);killsp();
  166.       }else{
  167.         v->clist=mymalloc(CLS);
  168.         v->clist->val.vint=val;
  169.         v->clist->next=v->clist->other=0;
  170.         v->clist->tree=0;
  171.       }
  172.       vlong=l2zl(1L);val=zladd(val,vlong);
  173.       v->vtyp->flags=CONST|ENUM;
  174.       if(*s!='}'&&*s!=',') {error(56);break;}
  175.       if(*s==',') s++;
  176.       killsp();
  177.       if(*s=='}') {s++; break;}
  178.     }
  179.       }
  180.       killsp();
  181.       typ=settyp(INT,typ);*buff=0;
  182.     }
  183.     if(!strcmp("void",buff)) {typ=settyp(VOID,typ);notdone=1;}
  184.     if(!strcmp("char",buff)) {typ=settyp(CHAR,typ);notdone=1;}
  185.     if(!strcmp("short",buff)) {typ=settyp(SHORT,typ);notdone=1;}
  186.     if(!strcmp("int",buff)) {typ=settyp(INT,typ);notdone=1;}
  187.     if(!strcmp("long",buff)) {typ=settyp(LONG,typ);notdone=1;}
  188.     if(!strcmp("float",buff)) {typ=settyp(FLOAT,typ);notdone=1;}
  189.     if(!strcmp("double",buff)) {typ=settyp(DOUBLE,typ);notdone=1;}
  190.     if(!strcmp("const",buff)){
  191.       if(type_qualifiers&CONST) error(58);
  192.       type_qualifiers|=CONST;notdone=1;
  193.     }
  194.     if(!strcmp("volatile",buff)){
  195.       if(type_qualifiers&VOLATILE) error(58);
  196.       type_qualifiers|=VOLATILE;notdone=1;
  197.     }
  198.     if(!strcmp("unsigned",buff)){
  199.       if(type_qualifiers&(XSIGNED|UNSIGNED)) error(58);
  200.       notdone=1;type_qualifiers|=UNSIGNED;
  201.     }
  202.     if(!strcmp("signed",buff)){
  203.       if(type_qualifiers&(XSIGNED|UNSIGNED)) error(58);
  204.       notdone=1;type_qualifiers|=XSIGNED;
  205.     }
  206.     if(!strcmp("auto",buff)) {dsc;storage_class=AUTO;notdone=1;}
  207.     if(!strcmp("register",buff)){dsc;storage_class=REGISTER;notdone=1;}
  208.     if(!strcmp("static",buff)) {dsc;storage_class=STATIC;notdone=1;}
  209.     if(!strcmp("extern",buff)) {dsc;storage_class=EXTERN;notdone=1;}
  210.     if(!strcmp("typedef",buff)) {dsc;storage_class=TYPEDEF;notdone=1;}
  211.     if(!(c_flags[7]&USEDFLAG)&&!strcmp("__reg",buff)){
  212.       char *d;int f=0;
  213.       killsp(); if(*s=='(') s++; else error(151);
  214.       killsp(); if(*s=='\"') s++; else error(74);
  215.       d=buff;
  216.       while(*s&&*s!='\"'){
  217.     if(d-buff-2>MAXI){
  218.       if(!f){ error(206,MAXI);f=1;}
  219.     }else *d++=*s;
  220.     s++;
  221.       }
  222.       *d=0;
  223.       if(*s=='\"') s++; else error(74);
  224.       killsp(); if(*s==')') s++; else error(59);
  225.       for(hard_reg=1;hard_reg<=MAXR;hard_reg++){
  226.     if(!strcmp(buff,regnames[hard_reg])) break;
  227.       }
  228.       if(hard_reg>MAXR){ hard_reg=0;error(220,buff);}
  229.       notdone=1;
  230.     }
  231.     
  232.     if(!notdone&&*buff&&typ==0&&!(type_qualifiers&(XSIGNED|UNSIGNED))){
  233.       v=find_var(buff,0);
  234.       if(v&&v->storage_class==TYPEDEF){
  235.     free(new);
  236.     new=clone_typ(v->vtyp);
  237.     typ=settyp(new->flags,typ);
  238.     notdone=1;
  239.       }
  240.     }
  241.     if(DEBUG&2) printf("typ:%d\n",typ);
  242.   }while(notdone);
  243.   s=merk;killsp();
  244.   return_sc=storage_class;
  245.   return_reg=hard_reg;
  246.   if(typ==0){
  247.     if(storage_class==0&&type_qualifiers==0) {free(new);return(0);}
  248.     typ=INT;
  249.   }
  250.   if(type_qualifiers&(XSIGNED|UNSIGNED))
  251.     if(typ!=INT&&typ!=CHAR&&typ!=LONG&&typ!=SHORT)
  252.       error(58);
  253.   if(DEBUG&2) printf("ts finish:%s\n",s);
  254.   new->flags=typ|type_qualifiers;
  255.   return(new);
  256. }
  257.  
  258. struct Typ *declarator(struct Typ *a)
  259. /* Erzeugt einen neuen Typ, auf Basis des Typs a.           */
  260. /* a wird hiermit verkettet.                                */
  261. {
  262.   struct Typ *t;
  263.   killsp();*ident=0;
  264.   t=direct_declarator(pointer(a));
  265.   if(!a) {if(t) freetyp(t);return(0);} else return(t);
  266. }
  267. struct Typ *pointer(struct Typ *a)
  268. /* Unterroutine fuer declaration(), behandelt Zeiger auf Typ.   */
  269. {
  270.   struct Typ *t;char *merk;int notdone;
  271.   if(!a) return(0);
  272.   killsp();
  273.   while(*s=='*'){
  274.     s++;
  275.     t=mymalloc(TYPS);
  276.     t->flags=POINTER;
  277.     t->next=a;
  278.     a=t;
  279.     do{
  280.       killsp();
  281.       merk=s;cpbez(buff,0);
  282.       notdone=0;
  283.       if(!strcmp("const",buff)) {a->flags|=CONST;notdone=1;}
  284.       if(!strcmp("volatile",buff)) {a->flags|=VOLATILE;notdone=1;}
  285.     }while(notdone);
  286.     s=merk;
  287.   }
  288.   return(a);
  289. }
  290.  
  291. struct Typ *direct_declarator(struct Typ *a)
  292. /*  Unterroutine zu declarator()                    */
  293. /*  behandelt [],(funkt),(dekl).                     */
  294. {
  295.   struct Typ *rek=0,*merk,*p,*t,*first,*last=0;
  296.   struct struct_declaration *fsd;
  297.   struct struct_list (*sl)[];
  298.   size_t slsz;
  299.   char *imerk,fbuff[MAXI];
  300.   killsp();
  301.   if(!isalpha((unsigned char)*s)&&*s!='_'&&*s!='('&&*s!='[') return(a);
  302.   if(isalpha((unsigned char)*s)||*s=='_'){
  303.     cpbez(ident,1);
  304.     if(!a) return(0);
  305.   }else if(*s=='('&&a){
  306.     /* Rekursion */
  307.     imerk=s; s++; killsp();
  308.     if(*s!=')'&&*ident==0&&!declaration(0)){
  309.       merk=a;
  310.       rek=declarator(a);
  311.       if(*s!=')') error(59); else s++;
  312.     }else s=imerk;
  313.   }
  314.   if(!a)return(0);
  315.   killsp();
  316.   while(*s=='['||*s=='('){
  317.     if(*s=='['){
  318.       s++;
  319.       killsp();
  320.       p=mymalloc(TYPS);
  321.       p->flags=ARRAY;
  322.       p->next=0;
  323.       if(*s==']'){
  324.     p->size=l2zl(0L);
  325.       }else{
  326.     np tree;
  327.     tree=expression();
  328.     if(!type_expression(tree)){
  329.       /*                    error("incorrect constant expression");*/
  330.     }else{
  331.       if(tree->sidefx) error(60);
  332.       if(tree->flags!=CEXPR||(tree->ntyp->flags&NQ)<CHAR||(tree->ntyp->flags&NQ)>LONG){
  333.         error(19);
  334.       }else{
  335.         eval_constn(tree);
  336.         p->size=vlong;
  337.         if(zleqto(p->size,l2zl(0L))) {error(61);p->size=l2zl(1L);}
  338.       }
  339.     }
  340.     free_expression(tree);
  341.       }
  342.       if(*s!=']') error(62); else s++;
  343.       if(last){
  344.     last->next=p;
  345.     last=p;
  346.       }else{
  347.     first=last=p;
  348.       }
  349.     }
  350.     if(*s=='('){
  351.       int komma,oldstyle=0;
  352. #ifdef HAVE_REGPARMS
  353.       struct reg_handle reg_handle=empty_reg_handle;
  354. #endif
  355.       s++;
  356.       killsp();
  357.       fsd=mymalloc(sizeof(*fsd));
  358.       slsz=SLSIZE;
  359.       sl=mymalloc(sizeof(struct struct_list)*slsz);
  360.       fsd->count=0;
  361.       imerk=ident;komma=0;
  362.       enter_block();
  363.       while(*s!=')'&&*s!='.'){
  364.     ident=fbuff;*fbuff=0;komma=0;
  365.     t=declarator(declaration_specifiers());
  366.     if(!t){
  367.       oldstyle=1;
  368.       if(*ident==0) {error(20);break;}
  369.     }
  370.     if(fsd->count){
  371.       if((t&&!(*sl)[fsd->count-1].styp)||
  372.          (!t&&(*sl)[fsd->count-1].styp))
  373.         error(63);
  374.     }
  375.     if(!return_sc) return_sc=AUTO;
  376.     if(return_sc!=AUTO&&return_sc!=REGISTER)
  377.       {error(21);return_sc=AUTO;}
  378.     (*sl)[fsd->count].styp=t;
  379.     (*sl)[fsd->count].storage_class=return_sc;
  380.     if(return_reg&&!regok(return_reg,t->flags,0)) error(217,regnames[return_reg]);
  381.     (*sl)[fsd->count].identifier=add_identifier(ident,strlen(ident));
  382.     if(t){
  383.       if(((*sl)[fsd->count].styp->flags&NQ)==VOID&&fsd->count!=0)
  384.         error(22);
  385.       /*  Arrays in Zeiger umwandeln  */
  386.       if(((*sl)[fsd->count].styp->flags&NQ)==ARRAY)
  387.         (*sl)[fsd->count].styp->flags=POINTER;
  388.       /*  Funktionen in Zeiger auf Funktionen umwandeln   */
  389.       if(((*sl)[fsd->count].styp->flags&NQ)==FUNKT){
  390.         struct Typ *new;
  391.         new=mymalloc(TYPS);
  392.         new->flags=POINTER;
  393.         new->next=(*sl)[fsd->count].styp;
  394.         (*sl)[fsd->count].styp=new;
  395.       }      
  396.     }
  397. #ifdef HAVE_REGPARMS
  398.     if(t) (*sl)[fsd->count].reg=reg_parm(®_handle,t);
  399.     if(return_reg) (*sl)[fsd->count].reg=return_reg;
  400. #else
  401.     (*sl)[fsd->count].reg=return_reg;
  402. #endif
  403.     fsd->count++;
  404.     if(fsd->count>=slsz-2){     /*  eins Reserve fuer VOID  */
  405.       slsz+=SLSIZE;
  406.       sl=realloc(sl,slsz*sizeof(struct struct_list));
  407.       if(!sl){error(12);raus();}
  408.     }
  409.     killsp(); /* Hier Syntaxpruefung strenger machen */
  410.     if(*s==',') {s++;komma=1; killsp();}
  411.       }
  412.       ident=imerk;
  413.       if((*s!='.'||*(s+1)!='.'||*(s+2)!='.')||!komma){
  414.     if(fsd->count>0&&(!(*sl)[fsd->count-1].styp||((*sl)[fsd->count-1].styp->flags&NQ)!=VOID)){
  415.       (*sl)[fsd->count].styp=mymalloc(TYPS);
  416.       (*sl)[fsd->count].styp->flags=VOID;
  417.       (*sl)[fsd->count].styp->next=0;
  418.       (*sl)[fsd->count].identifier=empty;
  419.       fsd->count++;
  420.     }
  421.       }else if(komma){
  422.     s+=3;komma=0;
  423.     if(oldstyle) error(221);
  424.       }
  425.       p=mymalloc(TYPS);
  426.       p->flags=FUNKT;
  427.       p->next=0;
  428.       {
  429.     int m=nesting;
  430.     nesting=0;
  431.     p->exact=add_sd(fsd);
  432.     add_sl(fsd,sl);
  433.     free(sl);
  434.     nesting=m;
  435.       }
  436.       killsp();
  437.       if(komma) error(59);
  438.       if(*s!=')') error(59); else s++;
  439.       killsp();
  440.       if(*s==','||*s==';'||*s==')'||*s=='=') leave_block();
  441.       if(last){
  442.     last->next=p;
  443.     last=p;
  444.       }else{
  445.     first=last=p;
  446.       }
  447.     }
  448.     killsp();
  449.   }
  450.   if(last){last->next=a;last=a;a=first;}
  451.   if(rek!=0&&rek!=merk){
  452.     /* Zweite Liste anhaengen */
  453.     p=rek;
  454.     while(p->next!=merk) p=p->next;
  455.     if(p) p->next=a; else ierror(0);
  456.     return(rek);
  457.   }
  458.   return(a);
  459. }
  460. int declaration(int offset)
  461. /*  Testet, ob eine Typangabe kommt. Wenn offset!=0 ist,    */
  462. /*  muss s auf '(' zeigen und es wird getestet, ob nach der */
  463. /*  Klammer eine Typangabe kommt.                           */
  464. /*  In jedem Fall zeigt s danach wieder auf dieselbe Stelle */
  465. /*  im Source.                                              */
  466. {
  467.   char *merk=s,buff[MAXI];
  468.   struct Var *v;
  469.   if(offset){
  470.     s++;
  471.     read_new_line=0;
  472.     if(DEBUG&1) printf("cleared read_new_line\n");
  473.     killsp();
  474.     if(read_new_line){  /*  es kam eine neue Zeile  */
  475.       memmove(s+1,s,MAXINPUT);
  476.       *s='(';
  477.       if(DEBUG&1) printf("look-ahead: %s|\n",s);
  478.       merk=s;
  479.       s++;
  480.       cpbez(buff,0);
  481.     }else{
  482.       if(DEBUG&1) printf("read_new_line unchanged\n");
  483.       cpbez(buff,0);
  484.     }
  485.   }else{
  486.     cpbez(buff,0);
  487.   }
  488.   s=merk;
  489.   if(!strcmp("auto",buff)) return(1);
  490.   if(!strcmp("char",buff)) return(1);
  491.   if(!strcmp("const",buff)) return(1);
  492.   if(!strcmp("double",buff)) return(1);
  493.   if(!strcmp("enum",buff)) return(1);
  494.   if(!strcmp("extern",buff)) return(1);
  495.   if(!strcmp("float",buff)) return(1);
  496.   if(!strcmp("int",buff)) return(1);
  497.   if(!strcmp("long",buff)) return(1);
  498.   if(!strcmp("register",buff)) return(1);
  499.   if(!strcmp("short",buff)) return(1);
  500.   if(!strcmp("signed",buff)) return(1);
  501.   if(!strcmp("static",buff)) return(1);
  502.   if(!strcmp("struct",buff)) return(1);
  503.   if(!strcmp("typedef",buff)) return(1);
  504.   if(!strcmp("union",buff)) return(1);
  505.   if(!strcmp("unsigned",buff)) return(1);
  506.   if(!strcmp("void",buff)) return(1);
  507.   if(!strcmp("volatile",buff)) return(1);
  508.   if(!(c_flags[7]&USEDFLAG)&&!strcmp("__reg",buff)) return(1);
  509.   v=find_var(buff,0);
  510.   if(v&&v->storage_class==TYPEDEF) return(1);
  511.   return(0);
  512. }
  513. void add_sl(struct struct_declaration *sd,struct struct_list (*sl)[])
  514. /*  Fuegt ein struct_list-Array in eine struct_declaration ein.     */
  515. /*  Das Array muss mind. sd->count Elements haben und wird kopiert. */
  516. {
  517.   size_t sz=sizeof(struct struct_list)*sd->count;
  518.   sd->sl=mymalloc(sz);
  519.   memcpy(sd->sl,sl,sz);
  520. }
  521. struct struct_declaration *add_sd(struct struct_declaration *new)
  522. /*  Fuegt eine struct Declaration in Liste ein.     */
  523. {
  524.   new->next=0;
  525.   if(first_sd[nesting]==0){
  526.     first_sd[nesting]=last_sd[nesting]=new;
  527.   }else{
  528.     last_sd[nesting]->next=new;
  529.     last_sd[nesting]=new;
  530.   }
  531.   return(new);
  532. }
  533. void free_sd(struct struct_declaration *p)
  534. /*  Gibt eine struct_declaration-List inkl. struct_lists und    */
  535. /*  allen Typen jeder struct_list frei, nicht aber identifier.  */
  536. {
  537.   int i;struct struct_declaration *merk;
  538.   while(p){
  539.     merk=p->next;
  540.     for(i=0;i<p->count;i++) if((*p->sl)[i].styp) freetyp((*p->sl)[i].styp);
  541.     if(p->count>0) free(p->sl);
  542.     free(p);
  543.     p=merk;
  544.   }
  545. }
  546. char *add_identifier(char *identifier,int length)
  547. /*  Kopiert identifier an sicheren Ort, der spaeter zentral     */
  548. /*  freigegeben werden kann.                                    */
  549. /*  Sollte noch einbauen, dass ueberprueft wird, ob schon       */
  550. /*  vorhanden und dann nicht zweimal speichern.                 */
  551. {
  552.   struct identifier_list *new;
  553.   if((*identifier==0&&length==0)||identifier==empty) return(empty);
  554.   new=mymalloc(sizeof(struct identifier_list));
  555.   new->identifier=mymalloc(length+1);
  556.   memcpy(new->identifier,identifier,length+1);
  557.   new->next=0;new->length=length;
  558.   if(last_ilist[nesting]){
  559.     last_ilist[nesting]->next=new;
  560.     last_ilist[nesting]=new;
  561.   }else{
  562.     last_ilist[nesting]=first_ilist[nesting]=new;
  563.   }
  564.   return(new->identifier);
  565. }
  566. void free_ilist(struct identifier_list *p)
  567. /*  Gibt eine verkettete identifier_liste und saemtliche darin  */
  568. /*  gespeicherten Identifier frei.                              */
  569. {
  570.   struct identifier_list *merk;
  571.   while(p){
  572.     merk=p->next;
  573.     if(p->identifier) free(p->identifier);
  574.     free(p);
  575.     p=merk;
  576.   }
  577. }
  578. int type_uncomplete(struct Typ *p)
  579. /*  Testet, ob Typ unvollstaendig ist. Momentan gelten nur      */
  580. /*  unvollstaendige Strukturen und Arrays von solchen als       */
  581. /*  unvollstaendig, aber keine Zeiger oder Funktionen darauf.   */
  582. {
  583.   struct struct_declaration *sd;
  584.   if(!p){ierror(0);return(0);}
  585.   if((p->flags&NQ)==STRUCT||(p->flags&NQ)==UNION)
  586.     if(p->exact->count<=0) return(1);
  587.   if((p->flags&NQ)==ARRAY){
  588.     if(zlleq(p->size,l2zl(0L))) return(1);
  589.     if(type_uncomplete(p->next)) return(1);
  590.   }
  591.   return(0);
  592. }
  593. void add_struct_identifier(char *identifier,struct struct_declaration *sd)
  594. /*  Erzeugt neuen struct_identifier, fuegt ihn in Liste an und  */
  595. /*  vervollstaendigt unvollstaendige Typen dieser Struktur.     */
  596. {
  597.   struct struct_identifier *new;
  598. /*    struct Typ *t;*/
  599.   if(DEBUG&1) printf("add_si %s (nesting=%d)->%p\n",identifier,nesting,(void *)sd);
  600.   new=mymalloc(sizeof(struct struct_identifier));
  601.   new->identifier=add_identifier(identifier,strlen(identifier));
  602.   new->sd=sd; new->next=0;
  603.   if(first_si[nesting]==0){
  604.     first_si[nesting]=new;last_si[nesting]=new;
  605.   }else{
  606.     last_si[nesting]->next=new;last_si[nesting]=new;
  607.   }
  608. }
  609. void free_si(struct struct_identifier *p)
  610. /*  Gibt eine struct_identifier-Liste frei, aber nicht die      */
  611. /*  identifiers und struct_declarations.                        */
  612. {
  613.   struct struct_identifier *merk;
  614.   while(p){
  615.     merk=p->next;
  616.     free(p);
  617.     p=merk;
  618.   }
  619. }
  620. struct struct_declaration *find_struct(char *identifier,int endnesting)
  621. /*  Sucht angegebene Strukturdefinition und liefert             */
  622. /*  entsprechende struct_declaration.                           */
  623. {
  624.   struct struct_identifier *si; int i;
  625.   for(i=nesting;i>=endnesting;i--){
  626.     si=first_si[i];
  627.     while(si){
  628.       if(!strcmp(si->identifier,identifier)){
  629.     if(DEBUG&1) printf("found struct tag <%s> at nesting %d->%p\n",identifier,i,(void *)si->sd);
  630.     return(si->sd);
  631.       }
  632.       si=si->next;
  633.     }
  634.   }
  635.   if(DEBUG&1) printf("didn't find struct tag <%s>\n",identifier);
  636.   return(0);
  637. }
  638. struct Var *add_tmp_var(struct Typ *t)
  639. {
  640.   return add_var(empty,t,AUTO,0);
  641. }
  642. struct Var *add_var(char *identifier, struct Typ *t, int storage_class,struct const_list *clist)
  643. /*  Fuegt eine Variable mit Typ in die var_list ein.            */
  644. /*  In der storage_class werden die Flags PARAMETER und evtl.   */
  645. /*  OLDSTYLE und REGPARM erkannt.                               */
  646. {
  647.   struct Var *new;int f;
  648.   struct struct_declaration *sd;
  649.   static zlong paroffset;
  650.   zlong al;
  651.   /*if(*identifier==0) return;*/ /* sollte woanders bemaekelt werden */
  652.   if(DEBUG&2) printf("add_var(): %s\n",identifier);
  653.   if((t->flags&NQ)==FUNKT&&((t->next->flags&NQ)==ARRAY||(t->next->flags&NQ)==FUNKT))
  654.     error(25);
  655.   new=mymalloc(sizeof(struct Var));
  656.   new->identifier=add_identifier(identifier,strlen(identifier));
  657.   new->clist=clist;
  658.   new->vtyp=t;
  659.   new->storage_class=storage_class&7;
  660.   new->reg=0;
  661.   new->next=0;
  662.   new->flags=0;
  663.   new->fi=0;
  664.   new->nesting=nesting;
  665.   /*    if((storage_class&7)==STATIC||(storage_class&7)==EXTERN) new->flags=USEDASSOURCE|USEDASDEST;*/
  666.   if(DEBUG&2) printf("storage_class=%d\n",storage_class);
  667.   if(storage_class&PARAMETER) new->flags|=USEDASDEST;
  668.   if(storage_class®PARM) {new->flags|=REGPARM;storage_class&=~PARAMETER;}
  669.   if(DEBUG&2) printf("storage_class=%d\n",storage_class);
  670.   if(DEBUG&2) printf("max_offset=%ld\n",max_offset);
  671.   if((storage_class&7)==REGISTER) new->priority=registerpri; else new->priority=0;
  672.   if(last_var[nesting]){
  673.     new->offset=zladd(last_var[nesting]->offset,szof(last_var[nesting]->vtyp));
  674.     last_var[nesting]->next=new;
  675.     last_var[nesting]=new;
  676.   }else{
  677.     new->offset=l2zl(0L);
  678.     paroffset=l2zl(0L);;
  679.     first_var[nesting]=last_var[nesting]=new;
  680.   }
  681.   f=t->flags&NQ;
  682.   if((storage_class&7)==AUTO||(storage_class&7)==REGISTER){
  683.     if(DEBUG&2) printf("auto\n");
  684.     if(type_uncomplete(t)&&(t->flags&NQ)!=ARRAY) error(202,identifier);
  685.     /*  das noch ueberpruefen   */
  686.     if((c_flags_val[0].l&2)&&nesting==1&&!(storage_class&PARAMETER)){
  687.       new->offset=max_offset;
  688.     }else{
  689.       if(storage_class&PARAMETER){
  690.     new->offset=paroffset;
  691.       }else{
  692.     new->offset=local_offset[nesting];
  693.       }
  694.     }
  695.     al=falign(t);
  696.     new->offset=zlmult(zldiv(zladd(new->offset,zlsub(al,l2zl(1L))),al),al);
  697.     if(storage_class&PARAMETER){
  698.       new->offset=zlmult(zldiv(zladd(new->offset,zlsub(maxalign,l2zl(1L))),maxalign),maxalign);
  699.       if(f>=CHAR&&f<=SHORT){
  700.     /*  Integer-Erweiterungen fuer alle Funktionsparameter  */
  701.     paroffset=zladd(new->offset,sizetab[INT]);
  702.       }else{
  703.     if(f==FLOAT&&(storage_class&OLDSTYLE)){
  704.       /*  Bei alten Funktionen werden FLOAT als DOUBLE uebergeben */
  705.       new->offset=zlmult(zldiv(zladd(new->offset,zlsub(align[DOUBLE],l2zl(1L))),align[DOUBLE]),align[DOUBLE]);
  706.       paroffset=zladd(new->offset,sizetab[DOUBLE]);
  707.     }else{
  708.       paroffset=zladd(new->offset,szof(new->vtyp));
  709.     }
  710.       }
  711.     }else{
  712.       local_offset[nesting]=zladd(new->offset,szof(new->vtyp));
  713.     }
  714.     
  715.     if(!(storage_class&PARAMETER))
  716.       if(zlleq(max_offset,local_offset[nesting])) max_offset=local_offset[nesting];
  717.     if(DEBUG&2) printf("max_offset=%ld\n",max_offset);
  718.   }
  719.   if((storage_class&7)==STATIC) new->offset=l2zl((long)++label);
  720.   if(storage_class&PARAMETER){
  721.     
  722.     if(DEBUG&2) printf("parameter\n");
  723.     
  724.     if(f>=CHAR&&f<=SHORT&&!zlleq(sizetab[INT],sizetab[f])){
  725.       if(BIGENDIAN){
  726.     new->offset=zladd(new->offset,zlsub(sizetab[INT],sizetab[f]));
  727.       }else{
  728.     if(!LITTLEENDIAN)
  729.       ierror(0);
  730.       }
  731.     }
  732.     if((storage_class&OLDSTYLE)&&f==FLOAT){
  733.       /*  Bei alten Funktionen werden DOUBLE nach FLOAT konvertiert   */
  734.       struct IC *conv=mymalloc(ICS);
  735.       conv->code=CONVDOUBLE;
  736.       conv->typf=FLOAT;
  737.       conv->q1.flags=VAR|DONTREGISTERIZE;
  738.       conv->z.flags=VAR;
  739.       conv->q2.flags=0;
  740.       conv->q1.v=conv->z.v=new;
  741.       conv->q1.val.vlong=conv->z.val.vlong=l2zl(0);
  742.       add_IC(conv);
  743.       new->flags|=CONVPARAMETER;
  744.     }
  745.     new->offset=zlsub(l2zl(0L),zladd(maxalign,new->offset));
  746.   }
  747.   if((storage_class&7)==EXTERN){
  748.     if(!strcmp("fprintf",identifier)) new->flags|=PRINTFLIKE;
  749.     if(!strcmp("printf",identifier))  new->flags|=PRINTFLIKE;
  750.     if(!strcmp("sprintf",identifier)) new->flags|=PRINTFLIKE;
  751.     if(!strcmp("fscanf",identifier))  new->flags|=SCANFLIKE;
  752.     if(!strcmp("scanf",identifier))   new->flags|=SCANFLIKE;
  753.     if(!strcmp("sscanf",identifier))  new->flags|=SCANFLIKE;
  754.   }
  755.   return(new);
  756. }
  757. void free_var(struct Var *p)
  758. /*  Gibt Variablenliste inkl. Typ, aber ohne Identifier frei.   */
  759. {
  760.   struct Var *merk;
  761.   while(p){
  762.     merk=p->next;
  763.     if(!(p->flags&USEDASADR)&&(p->storage_class==AUTO||p->storage_class==REGISTER)){
  764.       if(*p->identifier&&!(p->flags&USEDASDEST)&&(p->vtyp->flags&NQ)<=POINTER) error(64,p->identifier);
  765.       if(*p->identifier&&!(p->flags&USEDASSOURCE)&&(p->vtyp->flags&NQ)<=POINTER) error(65,p->identifier);
  766.     }
  767.     if(DEBUG&2) printf("free_var %s, pri=%d\n",p->identifier,p->priority);
  768.     if(p->vtyp) freetyp(p->vtyp);
  769.     if(p->clist) free_clist(p->clist);
  770.     if(p->fi){
  771.       if(DEBUG&2) printf("free_fi of function %s\n",p->identifier);
  772.       free_fi(p->fi);
  773.       if(DEBUG&2) printf("end free_fi of function %s\n",p->identifier);
  774.     }
  775.     free(p);
  776.     p=merk;
  777.   }
  778. }
  779. struct Var *find_var(char *identifier,int endnesting)
  780. /*  Sucht Variable mit Bezeichner und liefert Zeiger zurueck    */
  781. /*  es werden nur Variablen der Bloecke endnesting-nesting      */
  782. /*  durchsucht.                                                 */
  783. {
  784.   int i;struct Var *v;
  785.   if(*identifier==0||identifier==0) return(0);
  786.   for(i=nesting;i>=endnesting;i--){
  787.     v=first_var[i];
  788.     while(v){
  789.       if(!strcmp(v->identifier,identifier)) return(v);
  790.       v=v->next;
  791.     }
  792.   }
  793.   return(0);
  794. }
  795. void var_declaration(void)
  796. /*  Bearbeitet eine Variablendeklaration und erzeugt alle       */
  797. /*  noetigen Strukturen.                                        */
  798. {
  799.   struct Typ *ts,*t,*old=0,*om=0;char *imerk,vident[MAXI];
  800.   int mdef=0,makeint=0,notdone,storage_class,msc,extern_flag,isfunc,
  801.     had_decl,hard_reg,mhr;
  802.   struct Var *v;
  803.   ts=declaration_specifiers();notdone=1;
  804.   storage_class=return_sc;hard_reg=return_reg;
  805.   if(storage_class==EXTERN) extern_flag=1; else extern_flag=0;
  806.   killsp();
  807.   if(*s==';'){
  808.     if(storage_class||((ts->flags&NQ)!=STRUCT&&(ts->flags&NQ)!=UNION&&(ts->flags&NQ)!=INT))
  809.       error(36);
  810.     freetyp(ts);s++;killsp();
  811.     return;
  812.   }
  813.   if(nesting==0&&(storage_class==AUTO||storage_class==REGISTER))
  814.     {error(66);storage_class=EXTERN;}
  815.   if(!ts){
  816.     if(nesting<=1){
  817.       ts=mymalloc(TYPS);
  818.       ts->flags=INT;ts->next=0;
  819.       makeint=1;
  820.       if(!storage_class) storage_class=EXTERN;
  821.       error(67);
  822.     }else{
  823.       ierror(0);return;
  824.     }
  825.   }
  826.   if(storage_class==0){
  827.     if(nesting==0) storage_class=EXTERN; else storage_class=AUTO;
  828.   }
  829.   msc=storage_class;mhr=hard_reg;
  830.   while(notdone){
  831.     int oldnesting=nesting;
  832.     imerk=ident;ident=vident;*vident=0;  /* merken von ident hier vermutlich */
  833.     storage_class=msc;hard_reg=mhr;
  834.     if(old) {freetyp(old);old=0;}
  835.     t=declarator(clone_typ(ts));
  836.     if((t->flags&NQ)!=FUNKT) isfunc=0;
  837.     else {isfunc=1;if(storage_class!=STATIC) storage_class=EXTERN;}
  838.     ident=imerk;                    /* nicht unbedingt noetig ?         */
  839.     if(!*vident){
  840.       free(ts);free(t);
  841.       error(36);return;
  842.     }
  843.     v=find_var(vident,oldnesting);
  844.     if(v){
  845.       had_decl=1;
  846.       if(storage_class==TYPEDEF){
  847.     error(226,v->identifier);
  848.       }else{
  849.     if(nesting>0&&(v->flags&DEFINED)&&!extern_flag&&!isfunc){
  850.       error(27,vident);
  851.     }else{
  852.       if(t&&v->vtyp&&!compare_pointers(v->vtyp,t,255)){
  853.         error(68,vident);
  854.       }
  855.       if((storage_class!=v->storage_class&&!extern_flag)||hard_reg!=v->reg)
  856.         error(28,v->identifier);
  857.       if(!isfunc&&!extern_flag) v->flags|=TENTATIVE;
  858.     }
  859.     if(!isfunc){
  860.       v->vtyp=t;
  861.     }else{
  862.       om=v->vtyp;
  863.       if(t->exact->count>0) {old=v->vtyp;v->vtyp=t;}
  864.     }
  865.       }
  866.     }else{
  867.       had_decl=0;
  868.       if(isfunc&&*s!=','&&*s!=';'&&*s!=')'&&*s!='='&&nesting>0) nesting--;
  869.       v=add_var(vident,t,storage_class,0);
  870.       v->reg=hard_reg;
  871.       if(isfunc&&*s!=','&&*s!=';'&&*s!=')'&&*s!='='&&nesting>=0) nesting++;
  872.       if(!v) ierror(0);
  873.       else{
  874.     if(!isfunc&&!extern_flag){
  875.       v->flags|=TENTATIVE;
  876.       if(nesting>0) v->flags|=DEFINED;
  877.     }
  878.       }
  879.       om=0;
  880.     }
  881.     killsp();
  882.     /*  Inline-Assembler-Code in Funktionsdeklarationen */
  883.     if(*s=='='&&(v->vtyp->flags&NQ)==FUNKT&&!(c_flags[7]&USEDFLAG)){
  884.       np tree;
  885.       s++;killsp();
  886.       tree=string_expression();
  887.       if(!tree||tree->flags!=STRING) error(42);
  888.       else{
  889.     int l;struct const_list *cl;
  890.     if(!v->fi) v->fi=new_fi();
  891.     cl=tree->cl;l=0;
  892.     while(cl){
  893.       l++;
  894.       cl=cl->next;
  895.     }
  896.     v->fi->inline_asm=mymalloc(l);
  897.     cl=tree->cl;l=0;
  898.     while(cl){
  899.       v->fi->inline_asm[l]=zl2l(zc2zl(cl->other->val.vchar));
  900.       l++;
  901.       cl=cl->next;
  902.     }
  903.       }
  904.       if(tree) free_expression(tree);
  905.       killsp();
  906.     }           
  907.     /*  Initialisierung von Variablen bei Deklaration   */
  908.     if(*s=='='){
  909.       s++;killsp();
  910.       if(!had_decl&&v->nesting==0&&v->storage_class==EXTERN&&strcmp("main",v->identifier))
  911.     error(168,v->identifier);
  912.       if(v->flags&DEFINED) {if(nesting==0) error(30,v->identifier);}
  913.       else v->flags|=DEFINED;
  914.       if(v->storage_class==TYPEDEF) error(114,v->identifier);
  915.       if(extern_flag){
  916.     if(nesting==0)
  917.       error(118,v->identifier);
  918.     else
  919.       error(207,v->identifier);
  920.     if(v->storage_class!=EXTERN){ error(77);v->storage_class=EXTERN;}
  921.       }
  922.       v->clist=initialization(v->vtyp,v->storage_class==AUTO||v->storage_class==REGISTER,0);
  923.       if(v->clist){
  924.     if((v->vtyp->flags&NQ)==ARRAY&&zleqto(v->vtyp->size,l2zl(0L))){
  925.       struct const_list *p=v->clist;
  926.       while(p){v->vtyp->size=zladd(v->vtyp->size,l2zl(1L));p=p->next;}
  927.       if(v->storage_class==AUTO||v->storage_class==REGISTER){
  928.         local_offset[nesting]=zladd(local_offset[nesting],szof(v->vtyp));
  929.         if(zlleq(max_offset,local_offset[nesting])) max_offset=local_offset[nesting];
  930.       }
  931.     }
  932.     if(v->storage_class==AUTO||v->storage_class==REGISTER){
  933.       struct IC *new;
  934.       /*  Initialisierung von auto-Variablen  */
  935.       new=mymalloc(ICS);
  936.       new->code=ASSIGN;
  937.       new->typf=v->vtyp->flags;
  938.       new->q2.flags=0;
  939.       new->q2.val.vlong=szof(v->vtyp);
  940.       new->z.flags=VAR;
  941.       new->z.v=v;
  942.       new->z.val.vlong=l2zl(0L);
  943.       if(v->clist->tree){
  944.         /*  einzelner Ausdruck  */
  945.         gen_IC(v->clist->tree,0,0);
  946.         convert(v->clist->tree,v->vtyp->flags&NU);
  947.         new->q1=v->clist->tree->o;
  948.         /*                        v->clist=0;*/
  949.       }else{
  950.         /*  Array etc.  */
  951.         struct Var *nv;
  952.         nv=add_var(empty,clone_typ(v->vtyp),STATIC,v->clist);
  953.         nv->flags|=DEFINED;
  954.         nv->vtyp->flags|=CONST;
  955.         /*                        v->clist=0;*/
  956.         new->q1.flags=VAR;
  957.         new->q1.v=nv;
  958.         new->q1.val.vlong=l2zl(0L);
  959.       }
  960.       add_IC(new);
  961.       /*                    if(v->clist&&v->clist->tree){free_expression(v->clist->tree);v->clist->tree=0;}*/
  962.     }else if(c_flags[19]&USEDFLAG){
  963.       /*  Ohne Optimierung gleich erzeugen; das ist noch  */
  964.       /*  etwas von der genauen Implementierung der Liste */
  965.       /*  der Variablen abhaengig.                        */
  966.       struct Var *merk=v->next;
  967.       v->next=0;
  968.       gen_vars(v);
  969.       v->next=merk;
  970.       v->clist=0;
  971.     }
  972.       }
  973.     }else{
  974.       if((v->flags&DEFINED)&&type_uncomplete(v->vtyp)) error(202,v->identifier);
  975.       if((v->vtyp->flags&CONST)&&(v->storage_class==AUTO||v->storage_class==REGISTER))
  976.     error(119,v->identifier);
  977.     }
  978.     if(*s==',') {s++;killsp();mdef=1;} else notdone=0;
  979.   }
  980.   freetyp(ts);
  981.   if(!mdef&&t&&(t->flags&NQ)==FUNKT&&*s!=';'){
  982.     /*  Funktionsdefinition                                     */
  983.     int i,oldstyle=0;
  984. #ifdef HAVE_REGPARMS
  985.     struct reg_handle reg_handle;
  986. #endif
  987.     fline=line;
  988.     if(DEBUG&1) printf("Funktionsdefinition!\n");
  989.     {int i;
  990.     for(i=1;i<=MAXR;i++) {regs[i]=regused[i]=regsa[i];regsbuf[i]=0;}
  991.     }
  992.     cur_func=v->identifier;
  993.     if(only_inline==2) only_inline=0;
  994.     if(nesting<1) ierror(0);
  995.     if(nesting>1) error(32);
  996.     if(v->flags&DEFINED) error(33,v->identifier);
  997.     else v->flags|=DEFINED;
  998.     if(storage_class!=EXTERN&&storage_class!=STATIC) error(34);
  999.     if(extern_flag) error(120);
  1000.     if(storage_class==EXTERN&&!strcmp(v->identifier,"main")&&(!t->next||t->next->flags!=INT)) error(121);
  1001.     if(!had_decl&&v->nesting==0&&v->storage_class==EXTERN&&strcmp("main",v->identifier))
  1002.       error(168,v->identifier);
  1003.     while(*s!='{'){
  1004.       /*  alter Stil  */
  1005.       struct Typ *nt=declaration_specifiers();notdone=1;oldstyle=OLDSTYLE;
  1006.       if(!ts) {error(35);}
  1007.       while(notdone){
  1008.     int found=0;
  1009.     imerk=ident;ident=vident;*vident=0;
  1010.     ts=declarator(clone_typ(nt));
  1011.     ident=imerk;
  1012.     if(!ts) {error(36);}
  1013.     else{
  1014.       for(i=0;i<t->exact->count;i++){
  1015.         if(!strcmp((*t->exact->sl)[i].identifier,vident)){
  1016.           found=1;
  1017.           if((*t->exact->sl)[i].styp){
  1018.         error(69,vident);
  1019.         freetyp((*t->exact->sl)[i].styp);
  1020.           }
  1021.           /*  typ[] in *typ   */
  1022.           if((ts->flags&NQ)==ARRAY) ts->flags=POINTER;
  1023.           /*  typ() in *typ() */
  1024.           if((ts->flags&NQ)==FUNKT){
  1025.         struct Typ *new=mymalloc(TYPS);
  1026.         new->flags=POINTER;
  1027.         new->next=ts;
  1028.         ts=new;
  1029.           }
  1030.           if(!return_sc) return_sc=AUTO;
  1031.           if(return_sc!=AUTO&&return_sc!=REGISTER)
  1032.         {error(122);return_sc=AUTO;}
  1033.           (*t->exact->sl)[i].storage_class=return_sc;
  1034.           (*t->exact->sl)[i].reg=return_reg;
  1035.           if(return_reg) error(219);
  1036.           (*t->exact->sl)[i].styp=ts;
  1037.         }
  1038.       }
  1039.     }
  1040.     if(!found) {error(37,vident);}
  1041.     killsp();
  1042.     if(*s==',') {s++;killsp();} else notdone=0;
  1043.       }
  1044.       if(nt) freetyp(nt);
  1045.       if(*s==';'){s++;killsp();
  1046.       }else{
  1047.     error(54);
  1048.     while(*s!='{'&&*s!=';'){s++;killsp();}
  1049.       }
  1050.     }
  1051.     if(t->exact->count==0){
  1052.       struct struct_list sl[1];
  1053.       if(DEBUG&1) printf("prototype converted to (void)\n");
  1054.       t->exact->count=1;
  1055.       sl[0].identifier=empty;
  1056.       sl[0].storage_class=AUTO;
  1057.       sl[0].styp=mymalloc(TYPS);
  1058.       sl[0].styp->flags=VOID;
  1059.       sl[0].styp->next=0;
  1060.       nesting--;
  1061.       add_sl(t->exact,&sl);
  1062.       nesting++;
  1063.     }
  1064.     if(om&&!compare_sd(om->exact,t->exact))
  1065.       error(123);
  1066.     nocode=0;currentpri=1;
  1067.     /*        enter_block();*/
  1068.     local_offset[1]=l2zl(0L);
  1069.     return_var=0;
  1070.     if(!v->vtyp) ierror(0);
  1071. #ifdef HAVE_REGPARMS
  1072.     reg_handle=empty_reg_handle;
  1073. #endif
  1074.     if(v->vtyp->next->flags==VOID) return_typ=0;
  1075.     else{
  1076.       return_typ=v->vtyp->next;
  1077.       if(!freturn(return_typ)){
  1078.     /*  Parameter fuer die Rueckgabe von Werten, die nicht in einem */
  1079.     /*  Register sind.                                              */
  1080.     struct Typ *rt=mymalloc(TYPS);int reg;
  1081.     rt->flags=POINTER;rt->next=return_typ;
  1082. #ifdef HAVE_REGPARMS
  1083.     reg=reg_parm(®_handle,rt);
  1084.     if(!reg) ierror(0);
  1085.     return_var=add_var(empty,clone_typ(rt),AUTO|PARAMETER|REGPARM|oldstyle,0);
  1086.     return_var->reg=reg;
  1087. #else
  1088.     return_var=add_var(empty,clone_typ(rt),AUTO|PARAMETER|oldstyle,0);
  1089. #endif
  1090.     return_var->flags|=DEFINED;
  1091.     free(rt);
  1092.       }
  1093.     }
  1094.     first_ic=last_ic=0;ic_count=0;max_offset=l2zl(0L);
  1095.     for(i=0;i<t->exact->count;i++){
  1096.       if(!(*t->exact->sl)[i].styp&&*(*t->exact->sl)[i].identifier){
  1097.     struct Typ *nt;
  1098.     nt=mymalloc(TYPS);
  1099.     nt->flags=INT; nt->next=0;
  1100.     (*t->exact->sl)[i].styp=nt;
  1101.     (*t->exact->sl)[i].storage_class=AUTO;
  1102.     (*t->exact->sl)[i].reg=0;
  1103.     error(124);
  1104.       }
  1105.       if(*(*t->exact->sl)[i].identifier){
  1106.     struct Var *tmp;int sc;
  1107.     sc=((*t->exact->sl)[i].storage_class|PARAMETER|oldstyle);
  1108. #ifdef HAVE_REGPARMS
  1109.     if(!t->exact->sl) ierror(0);
  1110.     if(!(*t->exact->sl)[i].styp) ierror(0);
  1111.     (*t->exact->sl)[i].reg=reg_parm(®_handle,(*t->exact->sl)[i].styp);
  1112. #endif
  1113.     if((*t->exact->sl)[i].reg) sc|=REGPARM;
  1114.     tmp=add_var((*t->exact->sl)[i].identifier,clone_typ((*t->exact->sl)[i].styp),sc,0);
  1115.     tmp->reg=(*t->exact->sl)[i].reg;
  1116.     tmp->flags|=DEFINED;
  1117.     if(oldstyle){
  1118.       freetyp((*t->exact->sl)[i].styp);
  1119.       (*t->exact->sl)[i].styp=0; /*  Prototype entfernen */
  1120.     }
  1121.       }
  1122.     }
  1123.     if(oldstyle) t->exact->count=0; /*  Prototype entfernen */
  1124.     /*        local_offset[1]=l2zl(0L);*/
  1125.     return_label=++label;
  1126.     v->flags|=GENERATED;
  1127.     function_calls=0;float_used=0;has_return=0;goto_used=0;
  1128.     compound_statement();
  1129.     if((v->vtyp->next->flags&NQ)!=VOID&&!has_return){
  1130.       if(strcmp(v->identifier,"main")) error(173,v->identifier);
  1131.       else error(174,v->identifier);
  1132.     }
  1133. #if 0
  1134.     {int i;
  1135.     for(i=1;i<=MAXR;i++) if(regs[i]!=regsa[i]) {printf("Register %s:\n",regnames[i]);ierror(0);}
  1136.     }
  1137. #endif
  1138.         gen_label(return_label);
  1139.         if(first_ic&&errors==0){
  1140.       if((c_flags[2]&USEDFLAG)&&ic1){fprintf(ic1,"function %s\n",v->identifier); pric(ic1,first_ic);}
  1141.       vl1=first_var[0];
  1142.       vl2=first_var[1];
  1143.       vl3=merk_varf;
  1144.       optimize(c_flags_val[0].l,v);
  1145.       if((c_flags[3]&USEDFLAG)&&ic2){fprintf(ic2,"function %s\n",v->identifier); pric(ic2,first_ic);}
  1146.       if(out&&!only_inline&&!(c_flags[5]&USEDFLAG)){
  1147.         gen_code(out,first_ic,v,max_offset);
  1148.       }
  1149.       /*            if(DEBUG&8192){fprintf(ic2,"function %s, after gen_code\n",v->identifier); pric(ic2,first_ic);}*/
  1150.       free_IC(first_ic);
  1151.       first_ic=last_ic=0;
  1152.         }
  1153.         if(v->fi&&v->fi->first_ic){
  1154.       struct Var *vp;
  1155.       if(DEBUG&1) printf("leave block %d (inline-version)\n",nesting);
  1156.       if(nesting!=1) ierror(0);
  1157.       if(merk_varl) merk_varl->next=first_var[nesting]; else merk_varf=first_var[nesting];
  1158.       if(last_var[nesting]) merk_varl=last_var[nesting];
  1159.       if(merk_sil) merk_sil->next=first_si[nesting]; else merk_sif=first_si[nesting];
  1160.       if(last_si[nesting]) merk_sil=last_si[nesting];
  1161.       if(merk_sdl) merk_sdl->next=first_sd[nesting]; else merk_sdf=first_sd[nesting];
  1162.       if(last_sd[nesting]) merk_sdl=last_sd[nesting];
  1163.       if(merk_ilistl) merk_ilistl->next=first_ilist[nesting]; else merk_ilistf=first_ilist[nesting];
  1164.       if(last_ilist[nesting]) merk_ilistl=last_ilist[nesting];
  1165.       
  1166.       if(merk_varf&&!only_inline) gen_vars(merk_varf);
  1167.       if(first_llist) free_llist(first_llist);
  1168.       if(first_clist) free_clist(first_clist);
  1169.       if(merk_sif) free_si(merk_sif);
  1170. /*  struct-declarations erst ganz am Schluss loeschen. Um zu vermeiden,     */
  1171. /*  dass struct-declarations in Prototypen frei werden und dann eine        */
  1172. /*  spaetere struct, dieselbe Adresse bekommt und dadurch gleich wird.      */
  1173. /*  Nicht sehr schoen - wenn moeglich noch mal aendern.                     */
  1174. /*            if(merk_sdf) free_sd(merk_sdf);*/
  1175.             /*  hier noch was ueberlegen    */
  1176. /*            if(merk_ilistf) free_ilist(merk_ilistf);*/
  1177.       nesting--;
  1178.       v->fi->vars=merk_varf;
  1179. /*            v->fi->vars=first_var[1];*/
  1180.             /*  keine echten Parameter=>keine negativen Offsets */
  1181. /*            vp=first_var[1];*/
  1182.       vp=merk_varf;
  1183.       while(vp){
  1184.         if(vp->storage_class==AUTO||vp->storage_class==REGISTER){
  1185.           if(!zlleq(l2zl(0L),vp->offset)){
  1186.         vp->offset=l2zl(0L);
  1187.         if(DEBUG&1024) printf("converted parameter <%s>(%ld) for inlining\n",vp->identifier,(long)zl2l(vp->offset));
  1188.           }else vp->offset=l2zl(4L);  /*  Dummy, da recalc_offsets?   */
  1189.         }
  1190.         vp=vp->next;
  1191.       }
  1192.         }else{
  1193.       leave_block();
  1194.         }
  1195.         if(only_inline==2) only_inline=0;
  1196.         cur_func="oops, I forgot it";
  1197.   }else{
  1198.     if(makeint) error(125);
  1199.     if(*s==';') s++; else error(54);
  1200.     if((t->flags&NQ)==FUNKT&&t->exact){
  1201.       struct struct_declaration *sd=t->exact;int i,f;
  1202.       for(f=0,i=0;i<sd->count;i++)
  1203.     if(!(*sd->sl)[i].styp){error(126);f=1;}
  1204.       if(f){
  1205.     for(i=0;i<sd->count;i++) if((*sd->sl)[i].styp) freetyp((*sd->sl)[i].styp);
  1206.     sd->count=0;
  1207.       }
  1208.     }
  1209.   }
  1210.   if(old) freetyp(old);
  1211. }
  1212. int compare_pointers(struct Typ *a,struct Typ *b,int qual)
  1213. /*  Vergleicht, ob Typ beider Typen gleich ist, const/volatile      */
  1214. /*  werden laut ANSI nicht beruecksichtigt.                         */
  1215. {
  1216.   struct struct_declaration *sd;
  1217.   int af=a->flags&qual,bf=b->flags&qual;
  1218.   if(af!=bf) return(0);
  1219.   af&=NQ;bf&=NQ;
  1220.   if(af==FUNKT){
  1221.     if(a->exact->count&&!compare_sd(a->exact,b->exact)) return(0);
  1222.   }
  1223.   if(af==STRUCT||af==UNION){
  1224.     if(a->exact!=b->exact) return(0);
  1225.   }
  1226.   if(af==ARRAY){
  1227.     if(!zleqto(a->size,l2zl(0L))&&!zleqto(b->size,l2zl(0L))&&!zleqto(a->size,b->size)) return(0);
  1228.   }
  1229.   if(a->next==0&&b->next!=0) return(0);
  1230.   if(a->next!=0&&b->next==0) return(0);
  1231.   if(a->next==0&&b->next==0) return(1);
  1232.   return(compare_pointers(a->next,b->next,qual));
  1233. }
  1234. int compare_sd(struct struct_declaration *a,struct struct_declaration *b)
  1235. /*  Vergleicht, ob zwei struct_declarations identisch sind          */
  1236. /*  Wird nur nur fuer Prototypen benutzt, leere Liste immer gleich. */
  1237. {
  1238.   int i;
  1239.   if(!a->count||!b->count) return(1);
  1240.   if(a->count!=b->count) return(0);
  1241.   for(i=0;i<a->count;i++)
  1242.     if((*a->sl)[i].styp&&(*b->sl)[i].styp&&!compare_pointers((*a->sl)[i].styp,(*b->sl)[i].styp,255)) return(0);
  1243.   return(1);
  1244. }
  1245. void free_clist(struct const_list *p)
  1246. /*  Gibt clist frei.                                        */
  1247. {
  1248.   struct const_list *merk;
  1249.   return;
  1250.   while(p){
  1251.     merk=p->next;
  1252.     if(p->other) free_clist(p->other);
  1253.     if(p->tree) free_expression(p->tree);
  1254.     free(p);
  1255.     p=merk;
  1256.   }
  1257. }
  1258. void gen_clist(FILE *,struct Typ *,struct const_list *);
  1259.  
  1260. void gen_vars(struct Var *v)
  1261. /*  Generiert Variablen.                                    */
  1262. {
  1263.   int mode,al;struct Var *p;
  1264.   if(errors!=0||(c_flags[5]&USEDFLAG)) return;
  1265.   for(mode=0;mode<3;mode++){
  1266.     int i,flag;
  1267.     for(p=v;p;p=p->next){
  1268.       if(DEBUG&2) printf("gen_var(): %s\n",p->identifier);
  1269.       if(p->storage_class==STATIC||p->storage_class==EXTERN){
  1270.     if(!(p->flags&GENERATED)){
  1271.       if(p->storage_class==EXTERN&&!(p->flags&(USEDASSOURCE|USEDASDEST))&&!(p->flags&(TENTATIVE|DEFINED))) continue;
  1272.       /*  erst konstante initialisierte Daten */
  1273.       if(mode==0){
  1274.         if(!p->clist) continue;
  1275.         if(!(p->vtyp->flags&(CONST|STRINGCONST))){
  1276.           struct Typ *t=p->vtyp;int f=0;
  1277.           do{
  1278.         if(t->flags&(CONST|STRINGCONST)) break;
  1279.         if((t->flags&NQ)!=ARRAY){f=1;break;}
  1280.         t=t->next;
  1281.           }while(1);
  1282.           if(f) continue;
  1283.         }
  1284.       }
  1285.       /*  dann initiolisierte */
  1286.       if(mode==1&&!p->clist) continue;
  1287.       /*  und dann der Rest   */
  1288.       if(mode==2&&p->clist) continue;
  1289.       if(!(p->flags&(TENTATIVE|DEFINED))){
  1290.         gen_var_head(out,p);
  1291.         if(p->storage_class==STATIC) error(127,p->identifier);
  1292.         continue;
  1293.       }else{
  1294.         gen_align(out,falign(p->vtyp));
  1295.       }
  1296.       gen_var_head(out,p);
  1297.       if(!p->clist){
  1298.         if(type_uncomplete(p->vtyp)) error(202,p->identifier);
  1299.         gen_ds(out,szof(p->vtyp),p->vtyp);
  1300.       }else{
  1301.         gen_clist(out,p->vtyp,p->clist);
  1302.       }
  1303.       p->flags|=GENERATED;
  1304.     }
  1305.       }
  1306.     }   
  1307.   }
  1308. }
  1309. void gen_clist(FILE *f,struct Typ *t,struct const_list *cl)
  1310. /*  Generiert dc fuer const_list.                           */
  1311. {
  1312.   int i;zlong sz;
  1313.   if((t->flags&NQ)==ARRAY){
  1314.     for(sz=l2zl(0L);!zlleq(t->size,sz)&&cl;sz=zladd(sz,l2zl(1L)),cl=cl->next){
  1315.       if(!cl->other){ierror(0);return;}
  1316.       gen_clist(f,t->next,cl->other);
  1317.     }
  1318.     if(!zlleq(t->size,sz)) gen_ds(f,zlmult(zlsub(t->size,sz),szof(t->next)),t->next);
  1319.     return;
  1320.   }
  1321.   if((t->flags&NQ)==UNION){
  1322.     gen_clist(f,(*t->exact->sl)[0].styp,cl);
  1323.     sz=zlsub(szof(t),szof((*t->exact->sl)[0].styp));
  1324.     if(!zleqto(sz,l2zl(0L))) gen_ds(f,sz,0);
  1325.     return;
  1326.   }
  1327.   if((t->flags&NQ)==STRUCT){
  1328.     zlong al;int fl;struct Typ *st;
  1329.     sz=l2zl(0L);
  1330.     for(i=0;i<t->exact->count&&cl;i++){
  1331.       if(!cl->other){ierror(0);return;}
  1332.       st=(*t->exact->sl)[i].styp;
  1333.       al=falign(st);
  1334.       if(!zleqto(zlmod(sz,al),l2zl(0L))){
  1335.     gen_ds(f,zlsub(al,zlmod(sz,al)),0);
  1336.     sz=zladd(sz,zlsub(al,zlmod(sz,al)));
  1337.       }
  1338.       if(!(*t->exact->sl)[i].identifier) ierror(0);
  1339.       if((*t->exact->sl)[i].identifier[0]){
  1340.     gen_clist(f,st,cl->other);
  1341.     cl=cl->next;
  1342.       }else{
  1343.     gen_ds(f,szof(st),0); /* sollte unnamed bitfield sein */
  1344.       }
  1345.       sz=zladd(sz,szof(st));
  1346.     }
  1347.     for(;i<t->exact->count;i++){
  1348.       st=(*t->exact->sl)[i].styp;
  1349.       al=falign(st);
  1350.       if(!zleqto(zlmod(sz,al),l2zl(0L))){
  1351.     gen_ds(f,zlsub(al,zlmod(sz,al)),0);
  1352.     sz+=zladd(sz,zlsub(al,zlmod(sz,al)));
  1353.       }
  1354.       gen_ds(f,szof((*t->exact->sl)[i].styp),(*t->exact->sl)[i].styp);
  1355.       sz=zladd(sz,szof(st));
  1356.     }
  1357.     al=falign(t);
  1358.     if(!zleqto(zlmod(sz,al),l2zl(0L)))
  1359.       gen_ds(f,zlsub(al,zlmod(sz,al)),0);
  1360.     return;
  1361.   }
  1362.   if(cl->tree) cl->tree->o.am=0;
  1363.   gen_dc(f,t->flags&NU,cl);
  1364. }
  1365. struct const_list *initialization(struct Typ *t,int noconst,int level)
  1366. /*  Traegt eine Initialisierung in eine const_list ein.         */
  1367. {
  1368.   struct const_list *first,*cl,**prev;np tree,tree2;int bracket;zlong i;
  1369.   int f=t->flags&NQ;
  1370.   if(f==FUNKT){error(42);return(0);}
  1371.   if(*s=='{'){s++;killsp();bracket=1;} else bracket=0;
  1372.   if(f==ARRAY){
  1373.     if(*s=='\"'&&t->next&&(t->next->flags&NQ)==CHAR){
  1374.       killsp();
  1375.       tree=string_expression();
  1376.       first=tree->cl;
  1377.       free_expression(tree);
  1378.     }else{
  1379.       prev=0;
  1380.       if(level==0&&!bracket) error(157);
  1381.       for(i=l2zl(0L);(zleqto(t->size,l2zl(0L))||!zlleq(t->size,i))&&*s!='}';i=zladd(i,l2zl(1L))){
  1382.     if(!zlleq(i,0)){
  1383.       if(*s==','){s++;killsp();} else break;
  1384.       if(*s=='}') break;
  1385.     }
  1386.     cl=mymalloc(CLS);
  1387.     cl->next=0;cl->tree=0;
  1388.     cl->other=initialization(t->next,0,level+1);
  1389.     killsp();
  1390.     if(prev) *prev=cl; else first=cl;
  1391.     prev=&cl->next;
  1392.       }
  1393.     }
  1394.   }else if(f==STRUCT&&(bracket||!noconst)){
  1395.     if(t->exact->count<=0)
  1396.       {error(43);return(0);}
  1397.     prev=0;
  1398.     if(level==0&&!bracket) error(157);
  1399.     for(i=l2zl(0L);!zlleq(t->exact->count,i)&&*s!='}';i=zladd(i,l2zl(1L))){
  1400.       if((*t->exact->sl)[zl2l(i)].identifier[0]==0) {continue;} /* unnamed bitfield */
  1401.       if(!zlleq(i,0)){
  1402.     if(*s==','){s++;killsp();} else break;
  1403.     if(*s=='}') break;
  1404.       }
  1405.       cl=mymalloc(CLS);
  1406.       cl->next=0;cl->tree=0;
  1407.       cl->other=initialization((*t->exact->sl)[zl2l(i)].styp,0,level+1);
  1408.       if(prev) *prev=cl; else first=cl;
  1409.       prev=&cl->next;
  1410.     }
  1411.   }else if(f==UNION&&(bracket||!noconst)){
  1412.     if(t->exact->count<=0)
  1413.       {error(44);return(0);}
  1414.     first=initialization((*t->exact->sl)[0].styp,0,level+1);
  1415.   }else{
  1416.     tree2=tree=assignment_expression();
  1417.     if(!tree){error(45);return(0);}
  1418.     if(!type_expression(tree)){free_expression(tree); return(0);}
  1419.     tree=makepointer(tree);
  1420.     test_assignment(t,tree);
  1421.     if(!noconst){
  1422.       /*  nur Konstanten erlaubt (bei Arrays/Strukturen etc. oder static) */
  1423.       if(tree->flags!=CEXPR){
  1424.     while(tree->flags==CAST) tree=tree->left;
  1425.     if(tree->flags==ADDRESS||tree->flags==ADDRESSS||tree->flags==ADDRESSA){
  1426.       gen_IC(tree,0,0);
  1427.       if(!(tree->o.flags&VARADR)){
  1428.         /*  hier fehlen noch viele Pruefungen   */
  1429.         free_expression(tree);error(46);
  1430.         return(0);
  1431.       }
  1432.       first=mymalloc(CLS);
  1433.       first->next=first->other=0;
  1434.       first->tree=tree;
  1435.       killsp();
  1436.     }else{
  1437.       free_expression(tree);error(46);
  1438.       return(0);
  1439.     }
  1440.       }else{
  1441.     first=mymalloc(CLS);
  1442.     first->next=first->other=0;
  1443.     first->tree=0;
  1444.     eval_constn(tree);
  1445.     tree->ntyp->flags=t->flags;
  1446.     insert_const(tree);
  1447.     first->val=tree->val;
  1448.     free_expression(tree2);
  1449.     killsp();
  1450.       }
  1451.     }else{
  1452.       /*  auch anderes erlaubt    */
  1453.       first=mymalloc(CLS);
  1454.       first->next=first->other=0;
  1455.       first->tree=tree;
  1456.       killsp();
  1457.     }
  1458.   }
  1459.   if(bracket){
  1460.     if(*s==','){s++;killsp();}
  1461.     if(*s=='}'){s++;killsp();} else error(128);
  1462.   }
  1463.   return(first);
  1464. }
  1465.  
  1466.  
  1467.  
  1468.